package com.itheima.controller;

import aliyun.core.utils.AliOSSUtils;
import com.itheima.anno.Log;
import com.itheima.common.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class UploadController {

    @Autowired
    AliOSSUtils aliOSSUtils;
    @Log
    @PostMapping("/upload")
    public R upload(MultipartFile file) throws IOException {
        /*MultipartFile表示临时文件*/
        System.out.println(file.getOriginalFilename());
        System.out.println(file.getInputStream());
        //将临时文件保存到指定位置
        String upload = aliOSSUtils.upload(file);
        return R.ok(upload);
    }
}
